package com.ychug.gateway.cms;

import java.util.List;

import com.ychug.common.base.ResultAjaxHash;
import com.ychug.framework.web.base.BaseController;
import com.ychug.framework.web.page.TableDataInfo;
import com.ychug.service.cms.entity.CmsSiteEntity;
import com.ychug.service.cms.service.ICmsSiteService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 站点管理 信息操作处理
 * 
 * @author mcpcms
 * @date 2019-04-25
 */
@Controller
@RequestMapping("/cms/site")
public class CmsSiteController extends BaseController {
    private String prefix = "modules/cms/site";
	
	@Autowired
	private ICmsSiteService siteService;
	

	@GetMapping()
	public String site()
	{
	    return prefix + "/viewSite";
	}
	
	/**
	 * 查询站点管理列表
	 */

	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CmsSiteEntity site)
	{
		startPage();
        List<CmsSiteEntity> list = siteService.selectSiteList(site);
		return getDataTable(list);
	}
	
	/**
	 * 新增站点管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/addSite";
	}
	
	/**
	 * 新增保存站点管理
	 */


	@PostMapping("/add")
	@ResponseBody
	public ResultAjaxHash addSave(CmsSiteEntity site)
	{

		return toAjax(siteService.insertSite(site));
	}

	/**
	 * 修改站点管理
	 */
	@GetMapping("/edit/{siteId}")
	public String edit(@PathVariable("siteId") Integer siteId, ModelMap mmap)
	{
		CmsSiteEntity site = siteService.selectSiteById(siteId);
		mmap.put("site", site);
	    return prefix + "/editSite";
	}
	
	/**
	 * 修改保存站点管理
	 */

	@PostMapping("/edit")
	@ResponseBody
	public ResultAjaxHash editSave(CmsSiteEntity site)
	{		
		return toAjax(siteService.updateSite(site));
	}
	
	/**
	 * 删除站点管理
	 */

	@PostMapping( "/remove")
	@ResponseBody
	public ResultAjaxHash remove(String ids)
	{		
		return toAjax(siteService.deleteSiteByIds(ids));
	}
	
}
